﻿using Api.Common;
using Api.DBUtility;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Api.DAL
{
    /// <summary>
    /// 数据访问类:eazy_checked
    /// </summary>
    public partial class eazy_checked
    {
        private string databaseprefix = "eazy_"; //数据库表名前缀
        public eazy_checked()
        { }
        #region  BasicMethod
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from " + databaseprefix + "checked");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists_I(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) from " + databaseprefix + "checked");
            strSql.Append(" where instance_id=@instance_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@instance_id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            return DbHelperSQL.Exists(strSql.ToString(), parameters);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Models.eazy_checked model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 添加主表数据====================
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("insert into " + databaseprefix + "checked(");
                        strSql.Append("instance_id,b_name,b_mobile,b_address,b_business,b_represent,j_witnessed,j_company,c_name1,c_code1,c_name2,c_code2,s_time,e_time,projects,content,result,b_suggest,j_suggest,w_signature,b_signature,j_signature,z_signature,add_time)");
                        strSql.Append(" values (");
                        strSql.Append("@instance_id,@b_name,@b_mobile,@b_address,@b_business,@b_represent,@j_witnessed,@j_company,@c_name1,@c_code1,@c_name2,@c_code2,@s_time,@e_time,@projects,@content,@result,@b_suggest,@j_suggest,@w_signature,@b_signature,@j_signature,@z_signature,@add_time)");
                        strSql.Append(";select @@IDENTITY");
                        SqlParameter[] parameters = {
                                    new SqlParameter("@instance_id", SqlDbType.Int,4),
                                    new SqlParameter("@b_name", SqlDbType.NVarChar,100),
                                    new SqlParameter("@b_mobile", SqlDbType.NVarChar,20),
                                    new SqlParameter("@b_address", SqlDbType.NVarChar,255),
                                    new SqlParameter("@b_business", SqlDbType.NVarChar,100),
                                    new SqlParameter("@b_represent", SqlDbType.NVarChar,100),
                                    new SqlParameter("@j_witnessed", SqlDbType.NVarChar,100),
                                    new SqlParameter("@j_company", SqlDbType.NVarChar,100),
                                    new SqlParameter("@c_name1", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_code1", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_name2", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_code2", SqlDbType.NVarChar,20),
                                    new SqlParameter("@s_time", SqlDbType.DateTime),
                                    new SqlParameter("@e_time", SqlDbType.DateTime),
                                    new SqlParameter("@projects", SqlDbType.NText),
                                    new SqlParameter("@content", SqlDbType.NText),
                                    new SqlParameter("@result", SqlDbType.NText),
                                    new SqlParameter("@b_suggest", SqlDbType.NVarChar,255),
                                    new SqlParameter("@j_suggest", SqlDbType.NVarChar,255),
                                    new SqlParameter("@w_signature", SqlDbType.NVarChar,255),
                                    new SqlParameter("@b_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@j_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@z_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@add_time", SqlDbType.DateTime)};
                        parameters[0].Value = model.instance_id;
                        parameters[1].Value = model.b_name;
                        parameters[2].Value = model.b_mobile;
                        parameters[3].Value = model.b_address;
                        parameters[4].Value = model.b_business;
                        parameters[5].Value = model.b_represent;
                        parameters[6].Value = model.j_witnessed;
                        parameters[7].Value = model.j_company;
                        parameters[8].Value = model.c_name1;
                        parameters[9].Value = model.c_code1;
                        parameters[10].Value = model.c_name2;
                        parameters[11].Value = model.c_code2;
                        parameters[12].Value = model.s_time;
                        parameters[13].Value = model.e_time;
                        parameters[14].Value = model.projects;
                        parameters[15].Value = model.content;
                        parameters[16].Value = model.result;
                        parameters[17].Value = model.b_suggest;
                        parameters[18].Value = model.j_suggest;
                        parameters[19].Value = model.w_signature;
                        parameters[20].Value = model.b_signature;
                        parameters[21].Value = model.j_signature;
                        parameters[22].Value = model.z_signature;
                        parameters[23].Value = model.add_time;

                        //添加主表数据
                        object obj = DbHelperSQL.GetSingle(conn, trans, strSql.ToString(), parameters); //带事务
                        model.id = Convert.ToInt32(obj);
                        #endregion

                        #region 修改内容附件==========================
                        //删除已删除的附件
                        new case_attach().DeleteList_I(conn, trans, model.attach, model.instance_id);
                        // 添加/修改附件
                        if (model.attach != null)
                        {
                            StringBuilder strSql4;
                            foreach (Models.case_attach modelt in model.attach)
                            {
                                strSql4 = new StringBuilder();
                                if (modelt.id > 0)
                                {
                                    strSql4.Append("update " + databaseprefix + "case_attach set ");
                                    strSql4.Append("instance_id=@instance_id,");
                                    strSql4.Append("step_id=@step_id,");
                                    strSql4.Append("file_name=@file_name,");
                                    strSql4.Append("file_path=@file_path,");
                                    strSql4.Append("file_size=@file_size,");
                                    strSql4.Append("file_ext=@file_ext,");
                                    strSql4.Append("point=@point,");
                                    strSql4.Append("user_name=@user_name,");
                                    strSql4.Append("article_id=@article_id");
                                    strSql4.Append(" where id=@id");
                                    SqlParameter[] parameters4 = {
                                            new SqlParameter("@instance_id", SqlDbType.Int,4),
                                            new SqlParameter("@step_id", SqlDbType.Int,4),
                                            new SqlParameter("@file_name", SqlDbType.NVarChar,100),
                                            new SqlParameter("@file_path", SqlDbType.NVarChar,255),
                                            new SqlParameter("@file_size", SqlDbType.Int,4),
                                            new SqlParameter("@file_ext", SqlDbType.NVarChar,20),
                                            new SqlParameter("@point", SqlDbType.Int,4),
                                            new SqlParameter("@user_name", SqlDbType.NVarChar,20),
                                            new SqlParameter("@article_id", SqlDbType.Int,4),
                                            new SqlParameter("@id", SqlDbType.Int,4)};
                                    parameters4[0].Value = modelt.instance_id;
                                    parameters4[1].Value = modelt.step_id;
                                    parameters4[2].Value = modelt.file_name;
                                    parameters4[3].Value = modelt.file_path;
                                    parameters4[4].Value = modelt.file_size;
                                    parameters4[5].Value = modelt.file_ext;
                                    parameters4[6].Value = modelt.point;
                                    parameters4[7].Value = modelt.user_name;
                                    parameters4[8].Value = modelt.article_id;
                                    parameters4[9].Value = modelt.id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql4.ToString(), parameters4);
                                }
                                else
                                {
                                    strSql4.Append("insert into " + databaseprefix + "case_attach(");
                                    strSql4.Append("instance_id,step_id,file_name,file_path,file_size,file_ext,down_num,point,user_name,article_id)");
                                    strSql4.Append(" values (");
                                    strSql4.Append("@instance_id,@step_id,@file_name,@file_path,@file_size,@file_ext,@down_num,@point,@user_name,@article_id)");
                                    SqlParameter[] parameters4 = {
                                            new SqlParameter("@instance_id", SqlDbType.Int,4),
                                            new SqlParameter("@step_id", SqlDbType.Int,4),
                                            new SqlParameter("@file_name", SqlDbType.NVarChar,100),
                                            new SqlParameter("@file_path", SqlDbType.NVarChar,255),
                                            new SqlParameter("@file_size", SqlDbType.Int,4),
                                            new SqlParameter("@file_ext", SqlDbType.NVarChar,20),
                                            new SqlParameter("@down_num", SqlDbType.Int,4),
                                            new SqlParameter("@point", SqlDbType.Int,4),
                                            new SqlParameter("@user_name", SqlDbType.NVarChar,20),
                                            new SqlParameter("@article_id", SqlDbType.Int,4)};
                                    parameters4[0].Value = modelt.instance_id;
                                    parameters4[1].Value = modelt.step_id;
                                    parameters4[2].Value = modelt.file_name;
                                    parameters4[3].Value = modelt.file_path;
                                    parameters4[4].Value = modelt.file_size;
                                    parameters4[5].Value = modelt.file_ext;
                                    parameters4[6].Value = modelt.down_num;
                                    parameters4[7].Value = modelt.point;
                                    parameters4[8].Value = modelt.user_name;
                                    parameters4[9].Value = modelt.article_id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql4.ToString(), parameters4);
                                }
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return 0;
                    }
                }
            }
            return model.id;
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Models.eazy_checked model)
        {
            using (SqlConnection conn = new SqlConnection(DbHelperSQL.connectionString))
            {
                conn.Open();
                using (SqlTransaction trans = conn.BeginTransaction())
                {
                    try
                    {
                        #region 修改主表数据==========================
                        StringBuilder strSql = new StringBuilder();
                        strSql.Append("update " + databaseprefix + "checked set ");
                        strSql.Append("instance_id=@instance_id,");
                        strSql.Append("b_name=@b_name,");
                        strSql.Append("b_mobile=@b_mobile,");
                        strSql.Append("b_address=@b_address,");
                        strSql.Append("b_business=@b_business,");
                        strSql.Append("b_represent=@b_represent,");
                        strSql.Append("j_witnessed=@j_witnessed,");
                        strSql.Append("j_company=@j_company,");
                        strSql.Append("c_name1=@c_name1,");
                        strSql.Append("c_code1=@c_code1,");
                        strSql.Append("c_name2=@c_name2,");
                        strSql.Append("c_code2=@c_code2,");
                        strSql.Append("s_time=@s_time,");
                        strSql.Append("e_time=@e_time,");
                        strSql.Append("projects=@projects,");
                        strSql.Append("content=@content,");
                        strSql.Append("result=@result,");
                        strSql.Append("b_suggest=@b_suggest,");
                        strSql.Append("j_suggest=@j_suggest,");
                        strSql.Append("w_signature=@w_signature,");
                        strSql.Append("b_signature=@b_signature,");
                        strSql.Append("j_signature=@j_signature,");
                        strSql.Append("z_signature=@z_signature,");
                        strSql.Append("add_time=@add_time");
                        strSql.Append(" where id=@id");
                        SqlParameter[] parameters = {
                                    new SqlParameter("@instance_id", SqlDbType.Int,4),
                                    new SqlParameter("@b_name", SqlDbType.NVarChar,100),
                                    new SqlParameter("@b_mobile", SqlDbType.NVarChar,20),
                                    new SqlParameter("@b_address", SqlDbType.NVarChar,255),
                                    new SqlParameter("@b_business", SqlDbType.NVarChar,100),
                                    new SqlParameter("@b_represent", SqlDbType.NVarChar,100),
                                    new SqlParameter("@j_witnessed", SqlDbType.NVarChar,100),
                                    new SqlParameter("@j_company", SqlDbType.NVarChar,100),
                                    new SqlParameter("@c_name1", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_code1", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_name2", SqlDbType.NVarChar,20),
                                    new SqlParameter("@c_code2", SqlDbType.NVarChar,20),
                                    new SqlParameter("@s_time", SqlDbType.DateTime),
                                    new SqlParameter("@e_time", SqlDbType.DateTime),
                                    new SqlParameter("@projects", SqlDbType.NText),
                                    new SqlParameter("@content", SqlDbType.NText),
                                    new SqlParameter("@result", SqlDbType.NText),
                                    new SqlParameter("@b_suggest", SqlDbType.NVarChar,255),
                                    new SqlParameter("@j_suggest", SqlDbType.NVarChar,255),
                                    new SqlParameter("@w_signature", SqlDbType.NVarChar,255),
                                    new SqlParameter("@b_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@j_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@z_signature", SqlDbType.NVarChar,20),
                                    new SqlParameter("@add_time", SqlDbType.DateTime),
                                    new SqlParameter("@id", SqlDbType.Int,4)};
                        parameters[0].Value = model.instance_id;
                        parameters[1].Value = model.b_name;
                        parameters[2].Value = model.b_mobile;
                        parameters[3].Value = model.b_address;
                        parameters[4].Value = model.b_business;
                        parameters[5].Value = model.b_represent;
                        parameters[6].Value = model.j_witnessed;
                        parameters[7].Value = model.j_company;
                        parameters[8].Value = model.c_name1;
                        parameters[9].Value = model.c_code1;
                        parameters[10].Value = model.c_name2;
                        parameters[11].Value = model.c_code2;
                        parameters[12].Value = model.s_time;
                        parameters[13].Value = model.e_time;
                        parameters[14].Value = model.projects;
                        parameters[15].Value = model.content;
                        parameters[16].Value = model.result;
                        parameters[17].Value = model.b_suggest;
                        parameters[18].Value = model.j_suggest;
                        parameters[19].Value = model.w_signature;
                        parameters[20].Value = model.b_signature;
                        parameters[21].Value = model.j_signature;
                        parameters[22].Value = model.z_signature;
                        parameters[23].Value = model.add_time;
                        parameters[24].Value = model.id;

                        DbHelperSQL.ExecuteSql(conn, trans, strSql.ToString(), parameters);
                        #endregion

                        #region 修改内容附件==========================
                        //删除已删除的附件
                        new case_attach().DeleteList_I(conn, trans, model.attach, model.instance_id);
                        // 添加/修改附件
                        if (model.attach != null)
                        {
                            StringBuilder strSql4;
                            foreach (Models.case_attach modelt in model.attach)
                            {
                                strSql4 = new StringBuilder();
                                if (modelt.id > 0)
                                {
                                    strSql4.Append("update " + databaseprefix + "case_attach set ");
                                    strSql4.Append("instance_id=@instance_id,");
                                    strSql4.Append("step_id=@step_id,");
                                    strSql4.Append("file_name=@file_name,");
                                    strSql4.Append("file_path=@file_path,");
                                    strSql4.Append("file_size=@file_size,");
                                    strSql4.Append("file_ext=@file_ext,");
                                    strSql4.Append("point=@point,");
                                    strSql4.Append("user_name=@user_name,");
                                    strSql4.Append("article_id=@article_id");
                                    strSql4.Append(" where id=@id");
                                    SqlParameter[] parameters4 = {
                                            new SqlParameter("@instance_id", SqlDbType.Int,4),
                                            new SqlParameter("@step_id", SqlDbType.Int,4),
                                            new SqlParameter("@file_name", SqlDbType.NVarChar,100),
                                            new SqlParameter("@file_path", SqlDbType.NVarChar,255),
                                            new SqlParameter("@file_size", SqlDbType.Int,4),
                                            new SqlParameter("@file_ext", SqlDbType.NVarChar,20),
                                            new SqlParameter("@point", SqlDbType.Int,4),
                                            new SqlParameter("@user_name", SqlDbType.NVarChar,20),
                                            new SqlParameter("@article_id", SqlDbType.Int,4),
                                            new SqlParameter("@id", SqlDbType.Int,4)};
                                    parameters4[0].Value = modelt.instance_id;
                                    parameters4[1].Value = modelt.step_id;
                                    parameters4[2].Value = modelt.file_name;
                                    parameters4[3].Value = modelt.file_path;
                                    parameters4[4].Value = modelt.file_size;
                                    parameters4[5].Value = modelt.file_ext;
                                    parameters4[6].Value = modelt.point;
                                    parameters4[7].Value = modelt.user_name;
                                    parameters4[8].Value = modelt.article_id;
                                    parameters4[9].Value = modelt.id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql4.ToString(), parameters4);
                                }
                                else
                                {
                                    strSql4.Append("insert into " + databaseprefix + "case_attach(");
                                    strSql4.Append("instance_id,step_id,file_name,file_path,file_size,file_ext,down_num,point,user_name,article_id)");
                                    strSql4.Append(" values (");
                                    strSql4.Append("@instance_id,@step_id,@file_name,@file_path,@file_size,@file_ext,@down_num,@point,@user_name,@article_id)");
                                    SqlParameter[] parameters4 = {
                                            new SqlParameter("@instance_id", SqlDbType.Int,4),
                                            new SqlParameter("@step_id", SqlDbType.Int,4),
                                            new SqlParameter("@file_name", SqlDbType.NVarChar,100),
                                            new SqlParameter("@file_path", SqlDbType.NVarChar,255),
                                            new SqlParameter("@file_size", SqlDbType.Int,4),
                                            new SqlParameter("@file_ext", SqlDbType.NVarChar,20),
                                            new SqlParameter("@down_num", SqlDbType.Int,4),
                                            new SqlParameter("@point", SqlDbType.Int,4),
                                            new SqlParameter("@user_name", SqlDbType.NVarChar,20),
                                            new SqlParameter("@article_id", SqlDbType.Int,4)};
                                    parameters4[0].Value = modelt.instance_id;
                                    parameters4[1].Value = modelt.step_id;
                                    parameters4[2].Value = modelt.file_name;
                                    parameters4[3].Value = modelt.file_path;
                                    parameters4[4].Value = modelt.file_size;
                                    parameters4[5].Value = modelt.file_ext;
                                    parameters4[6].Value = modelt.down_num;
                                    parameters4[7].Value = modelt.point;
                                    parameters4[8].Value = modelt.user_name;
                                    parameters4[9].Value = modelt.article_id;
                                    DbHelperSQL.ExecuteSql(conn, trans, strSql4.ToString(), parameters4);
                                }
                            }
                        }
                        #endregion

                        trans.Commit();
                    }
                    catch
                    {
                        trans.Rollback();
                        return false;
                    }
                }
            }
            return true;
        }

        public void UpdateFields(int id, string strwhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update " + databaseprefix + "checked set " + strwhere);
            strSql.Append(" where id=" + id);
            DbHelperSQL.GetSingle(strSql.ToString());
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from " + databaseprefix + "checked ");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters);
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 批量删除数据
        /// </summary>
        public bool DeleteList(string idlist)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from " + databaseprefix + "checked ");
            strSql.Append(" where id in (" + idlist + ")  ");
            int rows = DbHelperSQL.ExecuteSql(strSql.ToString());
            if (rows > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.eazy_checked GetModel(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,b_name,b_mobile,b_address,b_business,b_represent,j_witnessed,j_company,c_name1,c_code1,c_name2,c_code2,s_time,e_time,projects,content,result,b_suggest,j_suggest,w_signature,b_signature,j_signature,z_signature,add_time,instance_id ");
            strSql.Append(" from " + databaseprefix + "checked");
            strSql.Append(" where id=@id");
            SqlParameter[] parameters = {
                    new SqlParameter("@id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Models.eazy_checked model = new Models.eazy_checked();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.eazy_checked GetModel_I(int id)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select  top 1 id,b_name,b_mobile,b_address,b_business,b_represent,j_witnessed,j_company,c_name1,c_code1,c_name2,c_code2,s_time,e_time,projects,content,result,b_suggest,j_suggest,w_signature,b_signature,j_signature,z_signature,add_time,instance_id ");
            strSql.Append(" from " + databaseprefix + "checked");
            strSql.Append(" where instance_id=@instance_id");
            SqlParameter[] parameters = {
                    new SqlParameter("@instance_id", SqlDbType.Int,4)
            };
            parameters[0].Value = id;

            Models.eazy_checked model = new Models.eazy_checked();
            DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters);
            if (ds.Tables[0].Rows.Count > 0)
            {
                return DataRowToModel(ds.Tables[0].Rows[0]);
            }
            else
            {
                return null;
            }
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Models.eazy_checked DataRowToModel(DataRow row)
        {
            Models.eazy_checked model = new Models.eazy_checked();
            if (row != null)
            {
                if (row["id"] != null && row["id"].ToString() != "")
                {
                    model.id = int.Parse(row["id"].ToString());
                }
                if (row["b_name"] != null)
                {
                    model.b_name = row["b_name"].ToString();
                }
                if (row["b_mobile"] != null)
                {
                    model.b_mobile = row["b_mobile"].ToString();
                }
                if (row["b_address"] != null)
                {
                    model.b_address = row["b_address"].ToString();
                }
                if (row["b_business"] != null)
                {
                    model.b_business = row["b_business"].ToString();
                }
                if (row["b_represent"] != null)
                {
                    model.b_represent = row["b_represent"].ToString();
                }
                if (row["j_witnessed"] != null)
                {
                    model.j_witnessed = row["j_witnessed"].ToString();
                }
                if (row["j_company"] != null)
                {
                    model.j_company = row["j_company"].ToString();
                }
                if (row["c_name1"] != null)
                {
                    model.c_name1 = row["c_name1"].ToString();
                }
                if (row["c_code1"] != null)
                {
                    model.c_code1 = row["c_code1"].ToString();
                }
                if (row["c_name2"] != null)
                {
                    model.c_name2 = row["c_name2"].ToString();
                }
                if (row["c_code2"] != null)
                {
                    model.c_code2 = row["c_code2"].ToString();
                }
                if (row["s_time"] != null && row["s_time"].ToString() != "")
                {
                    model.s_time = DateTime.Parse(row["s_time"].ToString());
                }
                if (row["e_time"] != null && row["e_time"].ToString() != "")
                {
                    model.e_time = DateTime.Parse(row["e_time"].ToString());
                }
                if (row["projects"] != null)
                {
                    model.projects = row["projects"].ToString();
                }
                if (row["content"] != null)
                {
                    model.content = row["content"].ToString();
                }
                if (row["result"] != null)
                {
                    model.result = row["result"].ToString();
                }
                if (row["b_suggest"] != null)
                {
                    model.b_suggest = row["b_suggest"].ToString();
                }
                if (row["j_suggest"] != null)
                {
                    model.j_suggest = row["j_suggest"].ToString();
                }
                if (row["w_signature"] != null)
                {
                    model.w_signature = row["w_signature"].ToString();
                }
                if (row["b_signature"] != null)
                {
                    model.b_signature = row["b_signature"].ToString();
                }
                if (row["j_signature"] != null)
                {
                    model.j_signature = row["j_signature"].ToString();
                }
                if (row["z_signature"] != null)
                {
                    model.z_signature = row["z_signature"].ToString();
                }
                if (row["add_time"] != null && row["add_time"].ToString() != "")
                {
                    model.add_time = DateTime.Parse(row["add_time"].ToString());
                }
                if (row["instance_id"] != null && row["instance_id"].ToString() != "")
                {
                    model.instance_id = int.Parse(row["instance_id"].ToString());
                }

                //附件
                model.attach = new case_attach().GetList_I(model.instance_id.ToString());
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select id,b_name,b_mobile,b_address,b_business,b_represent,j_witnessed,j_company,c_name1,c_code1,c_name2,c_code2,s_time,e_time,projects,content,result,b_suggest,j_suggest,w_signature,b_signature,j_signature,z_signature,add_time,instance_id ");
            strSql.Append(" FROM " + databaseprefix + "checked ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select ");
            if (Top > 0)
            {
                strSql.Append(" top " + Top.ToString());
            }
            strSql.Append(" id,b_name,b_mobile,b_address,b_business,b_represent,j_witnessed,j_company,c_name1,c_code1,c_name2,c_code2,s_time,e_time,projects,content,result,b_suggest,j_suggest,w_signature,b_signature,j_signature,z_signature,add_time,instance_id ");
            strSql.Append(" FROM " + databaseprefix + "checked ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            strSql.Append(" order by " + filedOrder);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获取记录总数
        /// </summary>
        public int GetRecordCount(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select count(1) FROM " + databaseprefix + "checked ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            object obj = DbHelperSQL.GetSingle(strSql.ToString());
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }

        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("SELECT * FROM ( ");
            strSql.Append(" SELECT ROW_NUMBER() OVER (");
            if (!string.IsNullOrEmpty(orderby.Trim()))
            {
                strSql.Append("order by T." + orderby);
            }
            else
            {
                strSql.Append("order by T.id desc");
            }
            strSql.Append(")AS Row, T.*  from " + databaseprefix + "checked T ");
            if (!string.IsNullOrEmpty(strWhere.Trim()))
            {
                strSql.Append(" WHERE " + strWhere);
            }
            strSql.Append(" ) TT");
            strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
            return DbHelperSQL.Query(strSql.ToString());
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select * FROM " + databaseprefix + "checked");
            strSql.Append(" where " + strWhere);
            recordCount = Convert.ToInt32(DbHelperSQL.GetSingle(PagingHelper.CreateCountingSql(strSql.ToString())));
            return DbHelperSQL.Query(PagingHelper.CreatePagingSql(recordCount, pageSize, pageIndex, strSql.ToString(), filedOrder));
        }
        #endregion
    }
}
